//
//  MyFavoryViewController.swift
//  koolcar
//
//  Created by xiantian on 2023/11/9.
//

import UIKit

class MyFavoryViewController: BaseViewController {
    var segmentView: ContactSegmentView!
    var scrollView: UIScrollView!
    
    var carFavoryView: MyFavoryCarView!
    var seaCarFavoryView: MyFavoryCarView!
    var productFavoryView: MyFavoryProductView!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.navBar.title = MMLocalizedString("my_favorite", comment: "我的收藏")
        self.navBar.wr_setBottomLineHidden(hidden: true)
        
        segmentView = ContactSegmentView.init(frame: CGRect.init(x: 0, y: NavBarHight, width: kScreenWidth, height: 54), titles: [
            MMLocalizedString("favory_local_title", comment: "本地车辆"),
            MMLocalizedString("favory_seacar_title", comment: "海外车辆"),
            MMLocalizedString("suer_reward_product", comment: "商品")
        ])
        segmentView.callBack = { [weak self] tag in
            self?.didSelectSegmentItem(index: tag)
        }
        self.view.addSubview(segmentView)
        
        ///
        let tempHeight: CGFloat = kScreenHeight - segmentView.frame.maxY
        scrollView = UIScrollView.init(frame: CGRect.init(x: 0, y: segmentView.frame.maxY, width: kScreenWidth, height: tempHeight))
        scrollView.contentSize = CGSize.init(width: kScreenWidth * 3, height: tempHeight)
        scrollView.isPagingEnabled = true
        scrollView.isScrollEnabled = true
        scrollView.showsVerticalScrollIndicator = false
        scrollView.showsHorizontalScrollIndicator = false
        self.view.addSubview(scrollView)
        
        //本地车辆
        carFavoryView = MyFavoryCarView.init(frame: CGRect.init(x: 0, y: 0, width: kScreenWidth, height: self.scrollView.frame.size.height))
        carFavoryView.changeFavoryCarView()
        scrollView.addSubview(carFavoryView)
        
        //海外车
        seaCarFavoryView = MyFavoryCarView.init(frame: CGRect.init(x: kScreenWidth, y: 0, width: kScreenWidth, height: self.scrollView.frame.size.height))
        seaCarFavoryView.seaCarFlag = true
        scrollView.addSubview(seaCarFavoryView)
        
        //商品
        productFavoryView = MyFavoryProductView.init(frame: CGRect.init(x: kScreenWidth*2, y: 0, width: kScreenWidth, height: self.scrollView.frame.size.height))
        scrollView.addSubview(productFavoryView)
    }
    
    
    private func didSelectSegmentItem(index: NSInteger) {
        switch index {
            case 0:
                //本地车
                carFavoryView.changeFavoryCarView()
            case 1:
                //海外车
                seaCarFavoryView.changeFavoryCarView()
            default:
                //商品
                productFavoryView.changeFavoryProductView()
        }
        
        UIView.animate(withDuration: 0.2) {
            self.scrollView.contentOffset.x = kScreenWidth * CGFloat(index)
        }
    }
   
}
